package res;

import gui.navigation.Navigator;

import java.util.Hashtable;

import javax.swing.Icon;
import javax.swing.ImageIcon;


public class IconManager {
	public static Hashtable<String,Icon> iconlib = new Hashtable<String,Icon>();
	public static Icon defaulticon = null;
	
	public static Icon getDefaultIcon(){
		if( defaulticon == null )
			loadres();
		
		return( defaulticon );
	}
	
	
	/**
	 * Load resource, usually you only need to reload these resource 
	 * one time.
	 * */
	private static void loadres(){
		if( loaded )
			return;
		
		Icon icon = new ImageIcon(Navigator.class.getResource("/res/console.png"));
		iconlib.put("console", icon);
		
		loaded = true;
	}
	
	private static boolean loaded = false;
	
	
	
	/**get a icon by its name*/
	public static Icon getIcon(String iconName){
		
		// check parameter
		if( ( iconName == null ) || (iconName.trim().length() < 1) )
			return null;
		
		// load resources if needed
		loadres();
		
		// get the icon
		Icon icon = iconlib.get( iconName.trim().toLowerCase() );
		return icon;			
	}
	
}
